(function(){
 
    //解决 redjs 跨域 ，不同源问题
     if(document.location.hostname.indexOf('.')<0)
            {
                   
                document.domain = document.location.hostname;
            }
            else
            {
                document.domain = document.location.hostname.substring(document.location.hostname.indexOf('.')+1);
            }
     
    //入口
    window.main = function ()
    {
        var app = this;
        app.checkSessionServiceName = "mission.account.checksession";
 
        var mdEditHeight = document.body.clientHeight - 90;
         
        var sdk = document.getElementById("sdk").value; 
        var key = document.getElementById("docKey").value; 
        var name = document.getElementById("docName").value; 
        var title = document.getElementById("docTitle").value; 
        var plugin = document.getElementById("pluginUrl").value; 
        var newIndexService = document.getElementById("newIndexService").value; 
        var getIndexService = document.getElementById("getIndexService").value; 
        var downloadService = document.getElementById("downloadService").value; 
        var uploadService = document.getElementById("uploadService").value; 
        var showIndex = document.getElementById("showIndex").value==='true'; 
        var _fn = function(){
            //console.log('展示窗体');
            //展示窗体
            Rsd.create('Rsd.tool.MarkdownEditor',{
                src:plugin + '?h='+mdEditHeight,//通过 src 重新指定 编辑器位置
                key:key,
                draggable:false,
                float:false,
                header:false,
                closeBtn:false,
                showIndex:showIndex,
                width:'100%',
                height:'100%', 
                data:{
                    Id:'',
                    Key:key,
                    Type:'home',
                    Title:title,
                    Name:name,
                },
                //后端服务标准接口 
                services:{
                    /**
                    * 文档索引编辑函数
                    */
                    newIndex:newIndexService,
                    /**
                     * 文档索引加载函数
                     */
                    getIndex:getIndexService,
                    /**
                     * 文件下载服务名称
                     */
                    downloadFile:downloadService,
                    /**
                     * 上传
                     */
                    uploadFile:uploadService,
                }, 
                editorHeight:mdEditHeight,
                mdContent:"#欢迎使用红微协同办公服务\r\n##这是一个markdown编辑器，需要开通云端账号才能使用完整的协作功能",
                
            }).showDialog(); 
        }
         
        if (rsd.app.containsService(downloadService)) {
            _fn();
        }
        else {  
            //console.log('注册事件：' + sdk + '-api');
            rsd.app.on(sdk + '-api', _fn); 
        }
    }    

})()